2 class GIFHandlerTest
extends MediaWikiTestCase
{
4 protected function setUp() {
7 $this->filePath
= __DIR__
. '/../../data/media';
8 $this->backend
= new FSFileBackend( array(
9 'name' => 'localtesting',
10 'lockManager' => 'nullLockManager',
11 'containerPaths' => array( 'data' => $this->filePath
)
13 $this->repo
= new FSRepo( array(
15 'url' => 'http://localhost/thumbtest',
16 'backend' => $this->backend
18 $this->handler
= new GIFHandler();
21 public function testInvalidFile() {
22 $res = $this->handler
->getMetadata( null, $this->filePath
. '/README' );
23 $this->assertEquals( GIFHandler
::BROKEN_FILE
, $res );
27 * @param $filename String basename of the file to check
28 * @param $expected boolean Expected result.
29 * @dataProvider provideIsAnimated
31 public function testIsAnimanted( $filename, $expected ) {
32 $file = $this->dataFile( $filename, 'image/gif' );
33 $actual = $this->handler
->isAnimatedImage( $file );
34 $this->assertEquals( $expected, $actual );
36 public static function provideIsAnimated() {
38 array( 'animated.gif', true ),
39 array( 'nonanimated.gif', false ),
44 * @param $filename String
45 * @param $expected Integer Total image area
46 * @dataProvider provideGetImageArea
48 public function testGetImageArea( $filename, $expected ) {
49 $file = $this->dataFile( $filename, 'image/gif' );
50 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
51 $this->assertEquals( $expected, $actual );
53 public static function provideGetImageArea() {
55 array( 'animated.gif', 5400 ),
56 array( 'nonanimated.gif', 1350 ),
61 * @param $metadata String Serialized metadata
62 * @param $expected Integer One of the class constants of GIFHandler
63 * @dataProvider provideIsMetadataValid
65 public function testIsMetadataValid( $metadata, $expected ) {
66 $actual = $this->handler
->isMetadataValid( null, $metadata );
67 $this->assertEquals( $expected, $actual );
69 public static function provideIsMetadataValid() {
71 array( GIFHandler
::BROKEN_FILE
, GIFHandler
::METADATA_GOOD
),
72 array( '', GIFHandler
::METADATA_BAD
),
73 array( null, GIFHandler
::METADATA_BAD
),
74 array( 'Something invalid!', GIFHandler
::METADATA_BAD
),
75 array( 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}', GIFHandler
::METADATA_GOOD
),
80 * @param $filename String
81 * @param $expected String Serialized array
82 * @dataProvider provideGetMetadata
84 public function testGetMetadata( $filename, $expected ) {
85 $file = $this->dataFile( $filename, 'image/gif' );
86 $actual = $this->handler
->getMetadata( $file, "$this->filePath/$filename" );
87 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
90 public static function provideGetMetadata() {
92 array( 'nonanimated.gif', 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}' ),
93 array( 'animated-xmp.gif', 'a:4:{s:10:"frameCount";i:4;s:6:"looped";b:1;s:8:"duration";d:2.399999999999999911182158029987476766109466552734375;s:8:"metadata";a:5:{s:6:"Artist";s:7:"Bawolff";s:16:"ImageDescription";a:2:{s:9:"x-default";s:18:"A file to test GIF";s:5:"_type";s:4:"lang";}s:15:"SublocationDest";s:13:"The interwebs";s:14:"GIFFileComment";a:1:{i:0;s:16:"GIƒ·test·file";}s:15:"_MW_GIF_VERSION";i:1;}}' ),
97 private function dataFile( $name, $type ) {
98 return new UnregisteredLocalFile( false, $this->repo
,
99 "mwstore://localtesting/data/$name", $type );